import random

# 玩家数量
NUM_PLAYERS = 2
# 棋盘长度
BOARD_LENGTH = 50
# 飞机起飞位置
TAKE_OFF_POSITION = 0
# 飞机终点位置
FINISH_POSITION = BOARD_LENGTH - 1

# 初始化玩家信息
def initialize_players():
    players = []
    for i in range(NUM_PLAYERS):
        players.append({
            "position": TAKE_OFF_POSITION,
            "name": f"Player {i + 1}"
        })
    return players

# 掷骰子
def roll_dice():
    return random.randint(1, 6)

# 移动玩家棋子
def move_player(player, steps):
    new_position = player["position"] + steps
    if new_position > FINISH_POSITION:
        # 超过终点要折返
        overshoot = new_position - FINISH_POSITION
        new_position = FINISH_POSITION - overshoot
    player["position"] = new_position
    return player

# 检查是否有玩家获胜
def check_winner(players):
    for player in players:
        if player["position"] == FINISH_POSITION:
            return player
    return None

# 主游戏循环
def main():
    players = initialize_players()
    current_player_index = 0

    while True:
        current_player = players[current_player_index]
        print(f"{current_player['name']}'s turn.")
        input("Press Enter to roll the dice...")
        dice_result = roll_dice()
        print(f"{current_player['name']} rolled a {dice_result}.")
        current_player = move_player(current_player, dice_result)
        print(f"{current_player['name']} is now at position {current_player['position']}.")

        winner = check_winner(players)
        if winner:
            print(f"{winner['name']} wins the game!")
            break

        # 切换到下一个玩家
        current_player_index = (current_player_index + 1) % NUM_PLAYERS

if __name__ == "__main__":
    main()